// @ts-check
const { Command, logger, ModeOptions, createServer } = require("f2e-server3")
const { createMiddleRBAC, createServiceFile } = require("f2e-middle-rbac")
const TailwindPlugin = require("@tailwindcss/postcss")
const app = new Command("assets-maker")
    .option('-m, --mode <mode>', 'server mode: dev, build or prod', 'dev', ModeOptions)
    .action(async (options) => {
        const service = createServiceFile({});
        require("./serve");
        const { mode } = options
        logger.setLevel('DEBUG')
        createServer({
            mode,
            gzip: true,
            buildFilter: pathname => /^(index|$)/.test(pathname),
            watchFilter: pathname => /^(index|src|$)/.test(pathname),
            outputFilter: pathname => /^(index|static|$)/.test(pathname),
            try_files: 'index.html',
            postcss: {
                entryPoints: {
                    in: 'src/main.css',
                    out: 'static/main.css',
                },
                plugins: [
                    TailwindPlugin({
                        optimize: mode === 'build',
                    }),
                ],
            },
            middlewares: [
                createMiddleRBAC(service),
            ],
            auth: {
                store: service.userService,
                white_list: [
                    '/api/project/export',
                ],
            },
            dest: 'output',
        })
    })

app.parse(process.argv)